// FileInfoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "remote.h"
#include "FileInfoDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFileInfoDlg dialog


CFileInfoDlg::CFileInfoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFileInfoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFileInfoDlg)
	m_bDoc =	TRUE;
	m_bHide = FALSE;
	m_bReadOnly = FALSE;
	m_strPath = _T("");
	m_strSize = _T("");
	m_strTime = _T("");
	//}}AFX_DATA_INIT
}


void CFileInfoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFileInfoDlg)
	DDX_Check(pDX, IDC_CHECK_DOC, m_bDoc);
	DDX_Check(pDX, IDC_CHECK_HIDE, m_bHide);
	DDX_Check(pDX, IDC_CHECK_READONLY, m_bReadOnly);
	DDX_Text(pDX, IDC_SHOW_PATH, m_strPath);
	DDX_Text(pDX, IDC_SHOW_SIZE, m_strSize);
	DDX_Text(pDX, IDC_SHOW_TIME, m_strTime);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFileInfoDlg, CDialog)
	//{{AFX_MSG_MAP(CFileInfoDlg)
	ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFileInfoDlg message handlers
void CFileInfoDlg::SetFileInfo(FILEINFO* fileInfo)
{
//	UpdateData();
	m_bReadOnly=fileInfo->IsReadOnly;
	m_bHide=fileInfo->IsHide;
	m_strPath=fileInfo->fileName;
	m_strTime=fileInfo->time;
	if(m_bHide |m_bReadOnly)
		m_bDoc=FALSE;
	m_strSize=IntToStr(fileInfo->len);
//	UpdateData(FALSE);
}

CString CFileInfoDlg::IntToStr(int num)
{
	int n;
	CString strFull="";
	CString temp="";
	n=num/1024;
	if(n==0)
	{
		strFull="1.0 KB";
		return strFull;
	}

	temp.Format("%d",n%1024);
	strFull=temp;
	while((n/=1024)!=0)
	{
//		n/=1024;
		temp.Format("%d",n%1024);
		strFull=temp+","+strFull;
	}

	strFull+=" KB";
	return strFull;
}

void CFileInfoDlg::OnRefresh() 
{
	// TODO: Add your control notification handler code here
	UpdateData(FALSE);
}

void CFileInfoDlg::OnOK() 
{
	// TODO: Add extra validation here
	m_bDoc =	TRUE;
	m_bHide = FALSE;
	m_bReadOnly = FALSE;
	m_strPath = _T("");
	m_strSize = _T("");
	m_strTime = _T("");
	UpdateData(FALSE);
	CDialog::OnOK();
}
